# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=kwin
pkgver=5.20.90
pkgrel=0
pkgdesc="An easy to use, but flexible, composited Window Manager"
# armhf blocked by qt5-qtdeclarative
# s390x blocked by kscreenlocker
arch="all !armhf !s390x !mips64"
url="https://kde.org/plasma-desktop/"
license="GPL-2.0-or-later AND (GPL-2.0-only OR GPL-3.0-only) AND LGPL-2.1-only"
depends="
	kirigami2
	qt5-qtmultimedia
	qt5-qtwayland
	xorg-server-xwayland
	"
depends_dev="
	breeze-dev
	eudev-dev
	fontconfig-dev
	kactivities-dev
	kcmutils-dev
	kcompletion-dev
	kconfig-dev
	kconfigwidgets-dev
	kcoreaddons-dev
	kcrash-dev
	kdeclarative-dev
	kdecoration-dev
	kglobalaccel-dev
	ki18n-dev
	kiconthemes-dev
	kidletime-dev
	kinit-dev
	kio-dev
	knewstuff-dev
	knotifications-dev
	kpackage-dev
	krunner-dev
	kscreenlocker-dev
	kservice-dev
	ktextwidgets-dev
	kwayland-dev
	kwayland-server-dev
	kwidgetsaddons-dev
	kwindowsystem-dev
	kxmlgui-dev
	lcms2-dev
	libdrm-dev
	libepoxy-dev
	libinput-dev
	libxi-dev
	libxkbcommon-dev
	mesa-dev
	mesa-gbm
	pipewire-dev
	plasma-framework-dev
	qt5-qtbase-dev
	qt5-qtdeclarative-dev
	qt5-qtscript-dev
	qt5-qtsensors-dev
	qt5-qtx11extras-dev
	wayland-dev
	xcb-util-cursor-dev
	xcb-util-image-dev
	xcb-util-wm-dev
	"
makedepends="$depends_dev
	extra-cmake-modules
	kdoctools-dev
	qt5-qttools-dev
	"
checkdepends="xvfb-run"

case "$pkgver" in
	*.90*) _rel=unstable;;
	*) _rel=stable;;
esac
source="https://download.kde.org/$_rel/plasma/$pkgver/kwin-$pkgver.tar.xz
	fix-build-with-musl.patch
	"
subpackages="$pkgname-dev $pkgname-doc $pkgname-lang"
options="!check" # Broken

prepare() {
	default_prepare

	# qmlplugindump fails for armv7+qemu (pmb#1970). This is purely for
	# packager knowledge and doesn't affect runtime, so we can disable it.
	if [ "$CARCH" = "armv7" ]; then
		for i in $(find -name CMakeLists.txt); do
			echo "Disabling ecm_find_qmlmodule in: $i"
			sed -i "s/ecm_find_qmlmodule/# ecm_find_qmlmodule/g" "$i"
		done
	fi
}

build() {
	cmake -B build \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE xvfb-run ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# kwin_wayland has CAP_SYS_NICE set. Because of this, libdbus doesn't trust the
	# environment and ignores it, causing for example keyboard shortcuts to not work
	# Remove CAP_SYS_NICE from kwin_wayland to make them work again
	setcap -r "$pkgdir"/usr/bin/kwin_wayland
}
sha512sums="6c2f3069c353820ce6f26b5175551d0998a5e859c3e2924d1126eafaa251d644bca5b1275672d3be3a4b358d30ae6f3ef5ccd62c64117110347c39cef630e9ef  kwin-5.20.90.tar.xz
7d4e3e009d1b198c2d6fe1306a1d7bf444a86edf58514484287fb39723a2750a0e7a74b739fe7795cb0fdf77c81e7c23cd582d47e90e3957434ceb09c26c7c6e  fix-build-with-musl.patch"
